﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LibraryManagement
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;
            string role = cmbRole.SelectedItem.ToString();

            string query = $"SELECT * FROM Users WHERE Username = '{username}' " +
                $"AND Password = '{password}' AND Role = '{role}'";
            DataTable dt = DatabaseHelper.ExecuteQuery(query);

            if (dt.Rows.Count > 0)
            {
                int userId = (int)dt.Rows[0]["UserID"];
                if (role == "管理员")
                {
                    AdminDashboard adminForm = new AdminDashboard(this);
                    adminForm.Show();
                    this.Hide();
                }
                else if (role == "读者")
                {
                    ReaderDashboard readerForm = new ReaderDashboard(this, userId);
                    readerForm.Show();
                    this.Hide();
                }
            }
            else
            {
                MessageBox.Show("登录失败，请检查用户名和密码！");
            }
        }
    }
}
